package com.sbj.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sbj.dto.req.QualityReq;
import com.sbj.dto.res.QualityRes;
import com.sbj.entity.Quality;
import com.sbj.mapper.QualityMapper;
import com.sbj.service.QualityService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/20 09:51
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class QualityServiceImpl extends ServiceImpl<QualityMapper, Quality> implements QualityService {

    @Override
    public Page<QualityRes> lists(QualityReq qualityReq) {
        Page<Quality> page=new Page<>(qualityReq.getPageNum(), qualityReq.getPageSize());
        LambdaQueryWrapper<Quality> like = Wrappers.lambdaQuery(Quality.class).like(Quality::getName, qualityReq.getName());
        return Convert.convert(new TypeReference<Page<QualityRes>>() {},this.page(page,like));
    }
}
